
<template>
  <!-- 账簿维护/经费账科目 页面-->
  <div>

    <cus-allcard :showTitle="false">
      <Tabs :value="tabsValue"
            style="padding-top:16px"
            @on-click="tabsValueChange($event)">
        <Tab-pane label="经费账科目"
                  name="nameOne">
          <div class="topBody">
            <div class="topBody-span"> 账簿年份</div>
            <Select v-model="selectModelOne"
                    placeholder="请选择账簿年份"
                    @on-change="selectModelChange(0)"
                    class="topBody-selects">
              <Option v-for="item in cityListOne"
                      :value="item.value"
                      :key="item.value">{{ item.label }}</Option>
            </Select>

            <cus-Button class="mr_10"
                        type="primary"
                        @onClick="addModelChange"
                        :disabled="selectModelOne==-1||cityListOne.length==1||isjiezhuanOne==1"
                        v-permission="20">添加科目</cus-Button>
          </div>

          <cusTable border
                 :loading="form.loading"
                 :columns="columnsOne"
                 :data="dataOne"
                 :draggable="true"
                 @on-drag-drop="onDragDrop"
                 :bottomClass="['cus-page']"
                 :size="vuex_config.tableSize"
                 @on-sort-change="filterChange($event)">

            <template slot-scope="{ row }"
                      slot="subjecttype1">
              {{row.subjecttype1==0?'主体科目':'分类科目'}}
            </template>
            <template slot-scope="{ row }"
                      slot="isinit">
              <Tag color="success"
                   v-if="row.isinit === '0'">是</Tag>
              <Tag color="error"
                   v-if="row.isinit === '1'">否</Tag>
            </template>

            <template slot-scope="{ row }"
                      slot="isvalid">
              <Tag color="success"
                   v-if="row.isvalid === 1">是</Tag>
              <Tag color="error"
                   v-if="row.isvalid === 0">否</Tag>
            </template>

            <template slot-scope="{ row }"
                      slot="operation">
              <div class="flex">
                <cus-button type="text"
                            size="small"
                            :style="(row.isinit=='0'||row.subjectlevel!=1)||isjiezhuanOne==1?'pointer-events: none;opacity: 0.2;color:#1E6FFF;padding:0 8px;':'color:#1E6FFF;padding:0 8px;' "
                            v-permission="20"
                            @onClick="tabelAddModelChange(row)">
                  添加分户
                </cus-button>
                <cus-button type="text"
                            size="small"
                            :style="row.isinit=='0'||isjiezhuanOne==1?'pointer-events: none;opacity: 0.2;color:#1E6FFF;padding:0 8px;':'color:#1E6FFF;padding:0 8px;' "
                            v-permission="30"
                            @onClick="tabelEditModelChange(row)">
                  修改
                </cus-button>
                <cus-button type="text"
                            size="small"
                            :style="row.isinit=='0'||isjiezhuanOne==1?'pointer-events: none;opacity: 0.2;color:#FF4746;padding:0 8px;':'color:#FF4746;padding:0 8px;' "
                            v-permission="40"
                            @onClick="tabelDeletModelChange(row)">
                  删除
                </cus-button>
              </div>
            </template>
          </cusTable>
          <div style="width: 100%; display: flex; justify-content: flex-end">
            <cus-page :data="pagesOne"
                      class="mt_10"
                      @pageChange="getAllSubjectApi(0)"></cus-page>
          </div>
        </Tab-pane>
        <Tab-pane label="粮秣账科目"
                  name="nameTwo">
          <div class="topBody">
            <div class="topBody-span"> 账簿年份</div>
            <Select v-model="selectModelTwo"
                    placeholder="请选择账簿年份"
                    @on-change="selectModelChange(1)"
                    class="topBody-selects">
              <Option v-for="item in cityListTwo"
                      :value="item.value"
                      :key="item.value">{{ item.label }}</Option>
            </Select>

            <cus-Button class="mr_10"
                        type="primary"
                        @onClick="addModelChange"
                        :disabled="selectModelTwo==-1||cityListTwo.length==1||isjiezhuanTwo==1"
                        v-permission="20">添加科目</cus-Button>
          </div>

          <cusTable border
                 :loading="form.loading"
                 :columns="columnsTwo"
                 :data="dataTwo"
                 :bottomClass="['cus-page']"
                 :size="vuex_config.tableSize"
                 @on-sort-change="filterChange($event)">
            <template slot-scope="{ row }"
                      slot="subjecttype1">
              {{row.subjecttype1==0?'主体科目':'分类科目'}}
            </template>
            <template slot-scope="{ row }"
                      slot="isinit">
              <Tag color="success"
                   v-if="row.isinit === '0'">是</Tag>
              <Tag color="error"
                   v-if="row.isinit === '1'">否</Tag>
            </template>

            <template slot-scope="{ row }"
                      slot="isvalid">
              <Tag color="success"
                   v-if="row.isvalid === 1">是</Tag>
              <Tag color="error"
                   v-if="row.isvalid === 0">否</Tag>
            </template>

            <template slot-scope="{ row }"
                      slot="operation">
              <div class="flex">
                <cus-button type="text"
                            size="small"
                            :style="(row.isinit=='0'||row.subjectlevel!=1)||isjiezhuanTwo==1?'pointer-events: none;opacity: 0.2;color:#1E6FFF;padding:0 8px;':'color:#1E6FFF;padding:0 8px;' "
                            v-permission="20"
                            @onClick="tabelAddModelChange(row)">
                  添加分户
                </cus-button>
                <cus-button type="text"
                            size="small"
                            v-permission="30"
                            :style="row.isinit=='0'||isjiezhuanTwo==1?'pointer-events: none;opacity: 0.2;color:#1E6FFF;padding:0 8px;':'color:#1E6FFF;padding:0 8px;' "
                            @onClick="tabelEditModelChange(row)">
                  修改
                </cus-button>
                <cus-button type="text"
                            size="small"
                            :style="row.isinit=='0'||isjiezhuanTwo==1?'pointer-events: none;opacity: 0.2;color:#FF4746;padding:0 8px;':'color:#FF4746;padding:0 8px;' "
                            v-permission="40"
                            @onClick="tabelDeletModelChange(row)">
                  删除
                </cus-button>
              </div>
            </template>
          </cusTable>
          <div style="width: 100%; display: flex; justify-content: flex-end">
            <cus-page :data="pagesTwo"
                      class="mt_10"
                      @pageChange="getAllSubjectApi(1)"></cus-page>
          </div>
        </Tab-pane>
      </Tabs>

    </cus-allcard>
    <cus-modal ref="Addmodal"
               title="添加科目"
               @on-visible-change="onVisibleChange"
               @onOk="onOkadd">
      <Form ref="formValidateAdd"
            :model="addform"
            :label-width="100">
        <FormItem label="科目名称"
                  prop="subjectname"
                  :rules="{required: true, message: '科目名称不能为空', trigger: 'blur'}">
          <Input v-model="addform.subjectname"
                 style="width: 200px"
                 maxlength="15"
                 placeholder="请输入科目名称"></Input>
        </FormItem>
        <FormItem label="科目类型">
          <Select v-model="addform.subjecttype1"
                  size="large"
                  placeholder="请选择科目类型"
                  @on-change="getNewSubjectCodeApi()"
                  style="width: 200px">
            <Option :value="0">主体科目</Option>
            <Option :value="1">分类科目</Option>
          </Select>
        </FormItem>
        <FormItem label="科目代码">
          <Input v-model="addform.subjectcode"
                 style="width: 200px"
                 :disabled="true"
                 placeholder="请输入科目代码"></Input>
        </FormItem>
        <FormItem label="是否在用">
          <Select v-model="addform.isvalid"
                  size="large"
                  placeholder="请选择是否在用"
                  style="width: 200px">
            <Option :value="1">是</Option>
            <Option :value="0">否</Option>
          </Select>
        </FormItem>

      </Form>
    </cus-modal>

    <cus-modal ref="tableAddmodal"
               title="添加分户"
               @on-visible-change="onVisibleChange"
               @onOk="onOktabelAdd">
      <Form ref="formValidateTableAdd"
            :model="tableaddform"
            :label-width="100">
        <FormItem label="科目名称"
                  prop="subjectname"
                  :rules="{required: true, message: '科目名称不能为空', trigger: 'blur'}">
          <Input v-model="tableaddform.subjectname"
                 style="width: 200px"
                 maxlength="15"
                 placeholder="请输入科目名称"></Input>
        </FormItem>
        <FormItem label="科目代码">
          <Input v-model="tableaddform.subjectcode"
                 style="width: 200px"
                 :disabled="true"
                 placeholder="请输入科目代码"></Input>
        </FormItem>
      </Form>
    </cus-modal>
    <cus-modal ref="Editmodal"
               title="修改科目"
               @on-visible-change="onVisibleChange"
               @onOk="onOkedit">
      <Form ref="formValidateEdit"
            :model="editform"
            :label-width="100">
        <FormItem label="科目名称"
                  prop="subjectname"
                  :rules="{required: true, message: '科目名称不能为空', trigger: 'blur'}">
          <Input v-model="editform.subjectname"
                 style="width: 200px"
                 placeholder="请输入科目名称"
                 maxlength="15"></Input>
        </FormItem>
        <FormItem label="科目类型">
          <Select v-model="editform.subjecttype1"
                  size="large"
                  placeholder="请选择科目类型"
                  style="width: 200px">
            <Option :value="0">主体科目</Option>
            <Option :value="1">分类科目</Option>
          </Select>
        </FormItem>
        <FormItem label="科目代码">
          <Input v-model="editform.subjectcode"
                 style="width: 200px"
                 :disabled="true"
                 placeholder="请输入科目代码"></Input>
        </FormItem>
        <FormItem label="是否在用">
          <Select v-model="editform.isvalid"
                  size="large"
                  placeholder="请选择是否在用"
                  style="width: 200px">
            <Option :value="1">是</Option>
            <Option :value="0">否</Option>
          </Select>
        </FormItem>

      </Form>
    </cus-modal>
  </div>
</template>
<script>
import {
  getAllSubject,
  getAccountBookListByUser,
  getAddSubject,
  getNewSubjectCode,
  getdeleteSubject,
  getmodifySubject,
  getChildSubjectCode,
  getaddChildSubject
} from '@/api/businessAccountingApi/essentialInformationApi'
import collapseArrow from '../../../../view/menu/systemManage/menuManage/components/collapseArrow.vue'

// import { store } from '/index'
// 表格修改功能
const editform = {
  subjectname: '', // 科目名称
  subjecttype1: 0, // 科目类别(默认0主体科目,1分类科目)
  subjectcode: '0', // 科目编码
  isvalid: 1, // 是否在用(默认0否 1是)
  isInit: 1, // 死参 是否初始化( 0是 默认1否)
  accountbookId: 1 // 账簿id
}
// 表格新添科目功能
const tableaddform = {
  subjectname: '', // 科目名称
  subjecttype1: 0, // 科目类别(默认0主体科目,1分类科目)
  subjectcode: '1', // 科目编码
  isvalid: 1, // 是否在用(默认0否 1是)
  isInit: 1, // 死参 是否初始化(0是 默认1否)
  accountbookId: 1, // 账簿id,
  partentid: 1// 父科目id
}
// 外部新添科目功能
const addform = {
  subjectname: '', // 科目名称
  subjecttype1: 0, // 科目类别(默认0主体科目,1分类科目)
  subjectcode: '1', // 科目编码
  isvalid: 1, // 是否在用(默认0否 1是)
  isInit: 1, // 死参 是否初始化(0是 默认1否)
  accountbookId: 1 // 账簿id
}
export default {
  components: { collapseArrow },
  data () {
    return {

      tabsValue: 'nameOne',
      form: {
        loading: false,
        name: '',
        startTime: '',
        endTime: ''
      },
      subjecttype: 0, // 0经费账 1粮秣账
      cityListOne: [], // 经费账-选择器-列表
      selectModelOne: -1, // 经费账-选择器-值
      dataOne: [], // 经费账-表格列表
      // 经费账-表头
      columnsOne: [
        {
          title: '序号',
          type: 'index',
          align: 'center',
          minWidth: 70
        },
        {
          title: '科目代码',
          key: 'subjectcode',
          align: 'center',
          // sortable: 'custom',
          minWidth: 100
        },
        {
          title: '科目名称',
          key: 'subjectname',
          align: 'center',
          minWidth: 100
        },
        // {
        //   title: '科目名称',
        //   key: 'subjectfullname',
        //   align: 'center',
        //   minWidth: 100
        // },
        {
          title: '科目类别',
          slot: 'subjecttype1',
          align: 'center',
          minWidth: 100
        },
        {
          title: '是否为初始化科目',
          slot: 'isinit',
          align: 'center',
          // sortable: 'custom',
          minWidth: 100
        },
        {
          title: '是否在用',
          slot: 'isvalid',
          align: 'center',
          // sortable: 'custom',
          minWidth: 100
        },
        {
          title: '操作',
          fixed: 'right', // 右侧固定
          slot: 'operation',
          align: 'center',
          minWidth: 180
        }
      ],
      // 经费账-分页
      pagesOne: {
        page: 1,
        pageSize: 10,
        pageTotal: 0
      },
      cityListTwo: [], // 经费账-选择器-列表
      selectModelTwo: -1, // 粮秣账-选择器-值
      dataTwo: [], // 粮秣账-表格列表
      // 粮秣账-表头
      columnsTwo: [
        {
          title: '序号',
          type: 'index',
          align: 'center',
          minWidth: 70
        },
        {
          title: '科目代码',
          key: 'subjectcode',
          align: 'center',
          sortable: 'custom',
          minWidth: 100
        },
        {
          title: '科目名称',
          key: 'subjectname',
          align: 'center',
          minWidth: 100
        },
        // {
        //   title: '科目名称',
        //   key: 'subjectfullname',
        //   align: 'center',
        //   minWidth: 100
        // },
        {
          title: '科目类别',
          slot: 'subjecttype1',
          align: 'center',
          minWidth: 100
        },
        {
          title: '是否为初始化科目',
          slot: 'isinit',
          align: 'center',
          sortable: 'custom',
          minWidth: 100
        },
        {
          title: '是否在用',
          slot: 'isvalid',
          align: 'center',
          sortable: 'custom',
          minWidth: 100
        },
        {
          title: '操作',
          fixed: 'right', // 右侧固定
          slot: 'operation',
          align: 'center',
          minWidth: 180
        }
      ],
      // 粮秣账-分页
      pagesTwo: {
        page: 1,
        pageSize: 10,
        pageTotal: 0
      },
      order: null, //筛选条件 (排序字段,是否在用:isvalid,科目代码:subjectcode)
      asc: null, //(0:正序,1倒序)
      // 添加科目表单
      addform: addform,
      // 表格添加科目表单
      tableaddform: tableaddform,
      // 表格修改科目表单
      editform: editform,
      subjectid: 0, // 删除经费账粮秣账接口传参id

      isjiezhuanOne: 0, //是否结转下年，作用：添加科目按钮置灰
      isjiezhuanTwo: 0 //是否结转下年，作用：添加科目按钮置灰
    }
  },
  mounted () {

    this.getAccountBookListByUserApi() // 根据用户id查询账簿-选择器使用
    this.getAllSubjectApi(0)// 默认查经费账     // 获取 经费账科目 或 粮秣账科目
  },

  methods: {
    // 拖拽功能
    onDragDrop (start, end) {
      start = parseInt(start)
      end = parseInt(end)
      let startData = this.dataOne[start]
      let endData = this.dataOne[end]
      // 移动
      // if (start < end) {
      //   for (let i = start + 1; i <= end; i++) {
      //     this.dataOne.splice(i - 1, 1, this.dataOne[i])
      //   }
      //   this.dataOne.splice(end, 1, startData)
      // }
      // if (start > end) {
      //   for (let i = start; i > end; i--) {
      //     this.dataOne.splice(i, 1, this.dataOne[i - 1])
      //   }
      //   this.dataOne.splice(end, 1, startData)
      // }
      // 置换
      this.dataOne.splice(start, 1, endData)
      this.dataOne.splice(end, 1, startData)

    },

    // 获取 经费账科目 或 粮秣账科目 接口
    getAllSubjectApi (ValuesubjectType) {
      let years
      let valueData
      if (ValuesubjectType === 0) { // 0经费账
        if (this.selectModelOne === -1) {
          years = ''
        } else {
          years = this.selectModelOne
        }
        valueData = {
          subjectType: ValuesubjectType, // 经费账、1粮秣账
          userid: this.vuex_user.base.id, // 用户id
          current: this.pagesOne.page,
          order: this.order,//(排序字段,是否在用:isvalid,科目代码:subjectcode)
          asc: this.asc,//(0:正序,1倒序)
          year: years,
          size: this.pagesOne.pageSize
        }
      } else { // 1粮秣账
        if (this.selectModelTwo === -1) {
          years = ''
        } else {
          years = this.selectModelTwo
        }
        valueData = {
          subjectType: ValuesubjectType, // 经费账、1粮秣账
          userid: this.vuex_user.base.id, // 用户id
          current: this.pagesTwo.page,
          order: this.order,//(排序字段,是否在用:isvalid,科目代码:subjectcode)
          asc: this.asc,//(0:正序,1倒序)
          year: years,
          size: this.pagesTwo.pageSize
        }
      }

      this.form.loading = true
      return new Promise(resolve => {
        getAllSubject(valueData).then((res) => {
          this.form.loading = false
          if (res.errorcode === 0) {
            if (ValuesubjectType === 0) { // 0经费账
              this.dataOne = res.subjectlist
              this.pagesOne.pageTotal = res.totalcount
            } else {
              this.dataTwo = res.subjectlist
              this.pagesTwo.pageTotal = res.totalcount
            }

            resolve()
          } else {
            this.$Message.error(res.resultmsg)
          }
        })
      })
    },
    // 根据用户id查询账簿-选择器使用 接口
    getAccountBookListByUserApi () {
      this.form.loading = true
      return new Promise((resolve) => {
        getAccountBookListByUser({
          userid: this.vuex_user.base.id // 用户id
        }).then((res) => {
          this.form.loading = false
          if (res.errorcode === 0) {
            res.accountbooklist.forEach(element => {
              element.value = element.year
              element.label = element.year
            })
            res.accountbooklist.unshift({ value: -1, label: '初始化数据' })
            this.cityListOne = res.accountbooklist
            if (this.cityListOne.length > 1) {
              this.selectModelOne = this.cityListOne[1].value
              this.addform.accountbookId = this.cityListOne[1].accountbookId// 添加科目接口使用 账簿id
              this.editform.accountbookId = this.cityListOne[1].accountbookId// 修改科目接口使用 账簿id、
              this.tableaddform.accountbookId = this.cityListOne[1].accountbookId// 表格科目接口使用 账簿id
            }
            this.cityListTwo = res.accountbooklist
            if (this.cityListTwo.length > 1) {
              this.selectModelTwo = this.cityListTwo[1].value
              this.addform.accountbookId = this.cityListTwo[1].accountbookId// 添加科目接口使用 账簿id
              this.editform.accountbookId = this.cityListTwo[1].accountbookId// 修改科目接口使用 账簿id、
              this.tableaddform.accountbookId = this.cityListTwo[1].accountbookId// 表格科目接口使用 账簿id
            }

            resolve()
          } else {
            this.$Message.error(res.resultmsg)
          }
        })
      })
    },
    // 添加科目 （经费账或粮秣账） 接口
    getAddSubjectApi () {
      let valueData = {
        subjectname: this.addform.subjectname, // 科目名称
        subjecttype1: this.addform.subjecttype1, // 科目类别(0主体科目,1分类科目)
        subjectcode: this.addform.subjectcode, // 科目编码
        isvalid: this.addform.isvalid, // 是否在用(0否1是)
        subjecttype: this.subjecttype, // 科目类型(0经费账,1粮秣帐)
        isInit: this.addform.isInit, // 是否初始化(0是1否)
        accountbookId: this.addform.accountbookId, // 账簿id
        userid: this.vuex_user.base.id // 用户id
      }
      this.form.loading = true
      return new Promise((resolve) => {
        getAddSubject(valueData).then((res) => {
          this.form.loading = false
          if (res.errorcode === 0) {
            this.$Message.success(res.resultmsg)
            this.getAllSubjectApi(this.subjecttype)// 粮秣账科目列表查询
            this.$refs['Addmodal'].show = false// 关闭添加科目弹框
            resolve()
          } else {
            this.$Message.error(res.resultmsg)
          }
        })
      })
    },
    // 查询科目代码 接口
    getNewSubjectCodeApi () {
      return new Promise(resolve => {
        getNewSubjectCode({
          subjecttype1: this.addform.subjecttype1,
          subjecttype: this.subjecttype, // 科目类型(0经费账,1粮秣帐)
          userid: this.vuex_user.base.id // 用户id
        }).then(res => {
          this.form.loading = false
          if (res.errorcode === 0) {
            this.addform.subjectcode = res.newsubjectcode// 添加科目弹框初始化值
            // this.addform.subjecttype1 = 0// 添加科目弹框初始化值
            // this.addform.isvalid = 1// 添加科目弹框初始化值
            resolve()
          } else {
            this.$Message.error(res.resultmsg)
            this.$refs['Addmodal'].show = false// 关闭添加科目弹框
          }
        })
      })
    },
    // 删除经费账科目或粮秣账科目 接口
    getdeleteSubjectApi () {
      return new Promise(resolve => {
        getdeleteSubject({
          subjectid: this.subjectid, // 科目类型(0经费账,1粮秣帐)
          userid: this.vuex_user.base.id // 用户id
        }).then(res => {
          this.form.loading = false
          if (res.errorcode === 0) {
            this.$Message.success(res.resultmsg)
            this.pagesTwo.page = 1
            this.pagesOne.page = 1
            this.getAllSubjectApi(this.subjecttype)// 刷新科目列表查询
            resolve()
          } else {
            this.$Message.error(res.resultmsg)
          }
        })
      })
    },
    // 修改保存经费账科目或粮秣账科目 接口
    getmodifySubjectApi () {
      let valueData = {
        subjectname: this.editform.subjectname, // 科目名称
        subjecttype1: this.editform.subjecttype1, // 科目类别(0主体科目,1分类科目)
        subjectcode: this.editform.subjectcode, // 科目编码
        isvalid: this.editform.isvalid, // 是否在用(0否1是)
        subjecttype: this.subjecttype, // 科目类型(0经费账,1粮秣帐)
        isInit: this.editform.isInit, // 是否初始化(0是1否)
        userid: this.vuex_user.base.id // 用户id
      }
      return new Promise(resolve => {
        getmodifySubject(valueData).then(res => {
          this.form.loading = false
          if (res.errorcode === 0) {
            this.$Message.success(res.resultmsg)
            this.getAllSubjectApi(this.subjecttype)// 刷新科目列表查询
            this.$refs['Editmodal'].show = false// 关闭添加科目弹框
            resolve()
          } else {
            this.$Message.error(res.resultmsg)
          }
        })
      })
    },
    // 获取分户科目代码 接口
    getChildSubjectCodeApi (valueId) {
      let valueData = {
        partentid: valueId,
        userid: this.vuex_user.base.id // 用户id
      }
      return new Promise(resolve => {
        getChildSubjectCode(valueData).then(res => {
          this.form.loading = false
          if (res.errorcode === 0) {
            this.tableaddform.subjectcode = res.code// 添加科目弹框初始化值
            this.$refs['tableAddmodal'].show = true// 打开添加科目弹框
            resolve()
          } else {
            this.$Message.error(res.resultmsg)
          }
        })
      })
    },
    // 添加分户科目 接口
    getaddChildSubjectApi () {
      let valueData = {
        subjectname: this.tableaddform.subjectname, // 科目名称
        subjecttype1: this.tableaddform.subjecttype1, // 科目类别(0主体科目,1分类科目)
        subjectcode: this.tableaddform.subjectcode, // 科目编码
        subjecttype: this.subjecttype, // 科目类型(0经费账,1粮秣帐)
        accountbookId: this.tableaddform.accountbookId, // 账簿id
        userid: this.vuex_user.base.id, // 用户id
        partentid: this.tableaddform.partentid// 父科目id
      }
      return new Promise(resolve => {
        getaddChildSubject(valueData).then(res => {
          this.form.loading = false
          if (res.errorcode === 0) {
            this.$Message.success(res.resultmsg)
            this.getAllSubjectApi(this.subjecttype)// 粮秣账科目列表查询
            this.$refs['tableAddmodal'].show = false// 关闭表格添加分户弹框
            resolve()
          } else {
            this.$Message.error(res.resultmsg)
          }
        })
      })
    },
    // tabs标签页改变回调
    tabsValueChange (value) {
      if (value === 'nameOne') { // 经费账科目
        this.subjecttype = 0 // 全局标明为经费账
        this.getAllSubjectApi(this.subjecttype)
      } else { // 粮秣账科目
        this.subjecttype = 1// 全局标明为粮秣
        this.getAllSubjectApi(this.subjecttype)
      }
    },
    // 账簿年份改变回调
    selectModelChange (value) {
      if (value === 0) { // 0为经费账
        this.pagesOne.page = 1 // 经费账-分页-重置
        this.pagesOne.pageSize = 10// 经费账-分页-重置
        this.getAllSubjectApi(0)// 经费账科目列表查询
        if (this.selectModelOne !== -1) {
          this.cityListOne.forEach(element => {
            if (element.value === this.selectModelOne) {
              this.addform.accountbookId = element.accountbookId// 添加科目接口使用 账簿id
              this.editform.accountbookId = element.accountbookId// 修改科目接口使用 账簿id、
              this.tableaddform.accountbookId = element.accountbookId// 表格科目接口使用 账簿id
              this.isjiezhuanOne = element.isjiezhuan //是否结转下年，作用：添加科目按钮置灰
            }
          })
        }
      } else { // 1为经费账
        this.pagesTwo.page = 1 // 粮秣账-分页-重置
        this.pagesTwo.pageSize = 10// 粮秣账-分页-重置
        this.getAllSubjectApi(1)// 粮秣账科目列表查询
        if (this.selectModelTwo !== -1) {
          this.cityListTwo.forEach(element => {
            if (element.value === this.selectModelTwo) {
              this.addform.accountbookId = element.accountbookId// 添加科目接口使用 账簿id
              this.editform.accountbookId = element.accountbookId// 修改科目接口使用 账簿id
              this.tableaddform.accountbookId = element.accountbookId// 修改科目接口使用 账簿id
              this.isjiezhuanTwo = element.isjiezhuan //是否结转下年，作用：添加科目按钮置灰
            }
          })
        }
      }
    },
    // 添加科目按钮
    addModelChange () {
      this.$refs['Addmodal'].show = true// 打开添加科目弹框
      this.getNewSubjectCodeApi()// 查询科目接口
    },
    // 添加科目表单验证
    onOkadd () {
      this.$refs['formValidateAdd'].validate(valid => {
        if (valid) {
          this.$nextTick(() => {
            this.getAddSubjectApi()// 添加科目 （经费账或粮秣账） 接口
          })
        }
      })
    },

    // 修改科目表单验证
    onOkedit () {
      this.$refs['formValidateEdit'].validate(valid => {
        if (valid) {
          this.$nextTick(() => {
            this.getmodifySubjectApi()// 修改保存经费账科目或粮秣账科目 接口
          })
        }
      })
    },
    // 弹框开启关闭变化触发
    onVisibleChange (v) {
      this.$refs['formValidateAdd'].resetFields()
      this.$refs['formValidateTableAdd'].resetFields()
      this.$refs['formValidateEdit'].resetFields()
      // if (!v) this.addform = this.$cu.deepClone(addform)
      // if (!v) this.editform = this.$cu.deepClone(editform)
    },
    // 表格修改科目按钮
    tabelEditModelChange (valueData) {
      this.$refs['Editmodal'].show = true// 打开弹框
      setTimeout(() => {
        this.editform.subjecttype1 = valueData.subjecttype1
        this.editform.subjectcode = valueData.subjectcode
        this.editform.isvalid = valueData.isvalid
        this.editform.isInit = valueData.isinit
        this.editform.subjectname = valueData.subjectname
      }, 100)
    },
    // 表格删除科目按钮
    tabelDeletModelChange (valueData) {
      this.$cu.dialog({ params: valueData }).then(({ subjectId }) => {
        this.subjectid = valueData.subjectId
        this.getdeleteSubjectApi()// 删除经费账科目或粮秣账科目 接口
      })
    },
    // 表格添加分户按钮
    tabelAddModelChange (valueData) {
      this.tableaddform.partentid = valueData.subjectId// 父科目id
      this.tableaddform.subjecttype1 = valueData.subjecttype1// 科目类别(0主体;1分类)
      this.getChildSubjectCodeApi(valueData.subjectId)// 获取分户科目代码 接口
    },
    // 表格添加分户表单验证
    onOktabelAdd () {
      this.$refs['formValidateTableAdd'].validate(valid => {
        if (valid) {
          this.$nextTick(() => {
            this.getaddChildSubjectApi()// 添加分户科目 接口
          })
        }
      })
    },

    // 点击筛选条件回调
    filterChange (value) {
      if (value.column.title == "科目代码") {
        this.order = 'subjectcode' // 科目代码
        this.asc = value.order == 'desc' ? 1 : 0
      } else if (value.column.title == "是否为初始化科目") {
        this.order = 'isinit' // 是否为初始化科目
        this.asc = value.order == 'desc' ? 1 : 0
      } else {
        this.order = 'isvalid' // 是否在用
        this.asc = value.order == 'desc' ? 0 : 1
      }
      this.getAllSubjectApi(this.subjecttype)// 刷新科目列表查询
    }
  }
}
</script>
<style lang="less" scoped>
.topBody {
  display: flex;
  margin-bottom: 20px;
  &-span {
    white-space: nowrap;
    line-height: 32px;
    width: 80px;
    text-align: right;
    font-size: 14px;
    color: rgba(0, 0, 0, 0.85) !important;
    margin-right: 10px;
  }
  &-selects {
    width: 200px;
    margin-right: 10px;
  }
}
</style>
